package com.kuangqiyuan.yatzygame.rule;

import com.kuangqiyuan.yatzygame.Play;

public abstract class AbstractRuleHandler {
  private AbstractRuleHandler nextHandler;
  private int level;

  protected Play play;

  public AbstractRuleHandler() {
    this.level = 0;
  }

  public void setNextHandler(AbstractRuleHandler handler) {
    this.nextHandler = handler;
  }

  public void setPlay(Play play) {
    this.play = play;
  }

  public final int handleRule(Play play) {
    this.play = play;

    int score = this.Count();

    if (this.nextHandler != null) {
      int nextRuleScore = this.nextHandler.handleRule(play);
      return Math.max(score, nextRuleScore);
    } else {
      return score;
    }
  }

  /**
   * 根据具体规则计算得分的方法
   * @return
   */
  public abstract int Count();
}
